﻿using System;
using System.IO;
using System.Data;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

using gKodes.IO;
using gKodes.Windows.Forms;

namespace gKodes.HexView.Sample
{
    public partial class FMain : Form
    {
        private FOptions mOptions;

        private FOffsetStates mOStates;

        public FMain()
        {
            InitializeComponent();
            this.mOStates = new FOffsetStates(this);
            this.mOptions = new FOptions(this);
            this.hVMain.IController.CaretOffsetChanged += new CaretOffsetEvent(OnCaretOffsetChanged);
        }

        private void OnCaretOffsetChanged(object sender, CaretOffsetEventArgs e)
        {
            this.tSSLOf.Text = string.Format("{0,8}", e.Offset);
        }

        private void oTSMIOpen_Click(object sender, EventArgs e)
        {
            if (this.oFDMain.ShowDialog() == DialogResult.OK)
            {
                this.hVMain.Source = new DataStream(File.OpenRead(this.oFDMain.FileName));
                this.tSSLSize.Text = string.Format("{0,8} bytes", this.hVMain.Source.Length);
                //this.hVMain.ChangeSource(new StreamSource(File.OpenRead(this.oFDMain.FileName)));
            }
        }

        private void oTSMIClose_Click(object sender, EventArgs e)
        {
            this.hVMain.Source = null;
            this.tSSLSize.Text = string.Format("{0:d,8} bytes", 0);
            this.tSSLOf.Text = string.Format("{0,8}", 0);
        }

        private void oTSMIExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.mOptions.ShowDialog();
        }

        private void tSSLOs_Click(object sender, EventArgs e)
        {
            this.mOStates.ShowDialog();
        }
    }
}
